<?php

namespace app\common\service;


use app\common\model\banxi\sys\SysMenu;
use app\common\model\banxi\sys\SysRoleMenu;

class MenuService extends ApiService
{
    public function createMenu($data)
    {
        $menuTableDef = new SysMenu();
        $dto = $data['dto'];
        $menuEndpoint = $data['menuEndpoint'];
        $permsList = array_map(function ($item) {
            return $item['perms'];
        }, $dto);
        $removeIdList = $menuTableDef->where(['menuEndpoint' => $menuEndpoint])
            ->whereNotIn('perms', $permsList)
            ->column('id');
        if (empty($removeIdList)) {
            $menuTableDef->where('id', 'in', $removeIdList)->delete();
            $sysRoleMenuModel = new SysRoleMenu();
            $sysRoleMenuModel->removeByMenuId($removeIdList, $menuEndpoint);
        }
        foreach ($dto as $item) {

        }
    }

}
